home *** CD-ROM | disk | FTP | other *** search
- // Copyright 1994 by Jon Dart. All Rights Reserved.
-
- #ifndef _SEARCH_H
- #define _SEARCH_H
-
- #include "board.h"
- #include "emove.h"
- #include "pinfo.h"
- #include "hash.h"
- #include "timectrl.h"
- #include "movegen.h"
- #include <time.h>
- #ifdef WINDOWS
- #include <windows.h>
- #endif
-
- class ReversibleMove;
-
- class Search
- {
- // Encapsulates alpha-beta search routine.
-
- public:
-
- enum StateType {Normal,Terminated,Check,Checkmate,
- Stalemate,Draw,Resigns};
-
- struct Statistics
- {
- StateType state;
- int value;
- Move best_line[Constants::MaxPly];
- time_t elapsed_time;
- unsigned plies_completed;
- unsigned max_depth;
- unsigned long num_moves;
- unsigned long num_pos;
- Statistics();
- void clear();
- };
-
- Search();
-
- ~Search();
-
- void terminate_now();
-
- Move find_best_move(
- #ifdef WINDOWS
- HWND hWnd,
- #endif
- const Board &ABoard,
- const Time_Info &ti,
- #ifdef WINDOWS
- const Boolean background,
- #endif
- Statistics &stats,
- Move &prev_move,
- Boolean use_previous_search );
-
- unsigned hints( const Board &ABoard,
- Move *moves,
- unsigned max_moves);
- // fill "moves" with up to "max_moves" hint moves, computed using
- // a minimal search depth.
-
- int get_ply() const;
- // return current depth of search.
-
- unsigned long get_numpos() const;
- // return # of positions evaluated
-
- time_t get_start_time() const
- {
- return start_time;
- }
-
- Search_Type get_search_type() const
- {
- return timeCtrl.get_search_type();
- }
-
- Search_Limit get_search_limit() const
- {
- return timeCtrl.get_search_limit();
- }
-
- ColorType get_side_to_move() const
- {
- return side_to_move;
- }
-
- Boolean is_background_search() const
- {
- return bkgrnd_search;
- }
-
- void set_time_up( const Boolean b )
- {
- time_up = b;
- }
-
- Boolean was_terminated() const
- {
- return terminated;
- }
-
- unsigned long get_time_limit() const
- {
- return time_target;
- }
-
- private:
- // make this class uncopyable:
- Search( const Search & );
- Search &operator = ( const Search & );
-
- int move_search(Board & ABoard, int alpha, int beta,
- const int ply, const Boolean princip_var,
- Boolean &terminate, Move *best_line);
- Boolean skip_move(const Board & ABoard, const unsigned ply,
- const unsigned limit,
- const ExtendedMove & emove, const Boolean in_check);
- int try_move(Board & ABoard, const ExtendedMove & emove,
- const int ply, int alpha, int &beta, const int rank,
- const Boolean pv, const Boolean forced,
- Boolean &terminate, Move *best_line);
- unsigned generate_moves(
- Board & board, Move_Generator & mg,
- const unsigned ply,
- Move * moves,
- const Boolean captures_only);
- int evalu8(const Board & board);
- Boolean is_draw( const Board &board, int &rep_count );
-
- unsigned long num_moves;
- unsigned plies_done;
- Move ply0moves[Move_Generator::MaxMoves];
- int ply0scores[Move_Generator::MaxMoves];
- int ply0move_count;
- int rank; // moves completed at ply 0
- Boolean ply0moves_generated;
- ExtendedMove *last_move; // array, size MaxPly
- Move *best_moves; // array, size MaxPly. Best move at
- // each ply
- int best_scores[Constants::MaxPly];
- Move *pv; // array, size MaxPly
- ReversibleMove *move_stack[Constants::MaxPly];
- Move *moves_generated[Constants::MaxPly]; // MaxMoves for each ply
- Move *candidates[Constants::MaxPly]; // MaxPly for each ply
- Boolean forced[Constants::MaxPly];
- Hash < Position_Info > *hash_table;
- int extend;
- Search::StateType state;
- ColorType side_to_move;
- Boolean terminated;
- Boolean bkgrnd_search;
- unsigned long time_target, time_added;
-
- #ifdef WINDOWS
- int search_number;
- static HACCEL accel;
- HWND my_hwnd;
- UINT idTimer;
- #endif
- time_t start_time;
- Time_Control timeCtrl;
- unsigned long num_pos;
- int max_depth; // nominal search limit
- int display_depth; // depth to display
- Boolean time_up, searching;
- #ifdef NULL_MOVE
- Boolean null_move;
- #endif
- };
-
- #endif
-
-